import 'package:flutter/material.dart';
import '../data/StaticData.dart';
import '../im/socket/service/RpcPullDataService.dart';
import '../im/socket/dto/business/PullData.dart';

class NewPage extends StatefulWidget {
  @override
  _NewPageState createState() => _NewPageState();
}

class _NewPageState extends State<NewPage> {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: double.infinity,
      color: Colors.black12,
      child: SingleChildScrollView(
          child: Column(
            children: newListGroups.map((listGroup) => _buildListGroup(listGroup)).toList(),
          )
      ),
    );
  }

  Widget _buildListGroup(ListGroup listGroup) {
    return Padding(
      padding: EdgeInsets.only(bottom: 5),
      child: Column(
        children: listGroup.childrens
            .asMap()
            .map((index, value) => MapEntry(index, _buildChild(index == listGroup.childrens.length - 1, value)))
            .values
            .toList(),
      ),
    );
  }

  Widget _buildChild(bool isLast, ListItem listItem) {
    var listTile = ListTile(
        dense: true,
        leading: listItem.icon,
        title: Text(listItem.name),
        trailing: listItem.routerLeft != '' ? Icon(Icons.arrow_right) : null,
        onTap: () {
          RpcPullDataService _pullDataService = new RpcPullDataService();
          DepartmentInfoListReq departmentInfoListReq = new DepartmentInfoListReq();
          departmentInfoListReq.pageSize = 1000;
          _pullDataService.pullDepartmentInfoList(departmentInfoListReq);
        },
    );
    var seperate = _buildSeperate();
    return Container(
      color: Colors.white,
      child: isLast
          ? listTile
          : Column(
              children: [listTile, seperate],
            ),
    );
  }

  Widget _buildSeperate() {
    return Padding(
      padding: EdgeInsets.only(left: 50),
      child: Divider(
        height: 1.0,
        indent: 0.0,
        color: Colors.black26,
      ),
    );
  }
}
